package com.nj.interfaces.login.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.nj.forward.user.login.vo.UserLoginVo;
import com.nj.framework.util.SpringMVCResult;
import com.nj.interfaces.login.service.UserService;
@Controller
public class LoginAction {

	@Autowired 
	private UserService userLoginService;

	/** 
	 * 方法名：  commonLogin 
	 * 描述：  登陆接口
	 * @author  吴志虎   
	 * @param request
	 * @param response
	 * @return
	 *
	 */
	@RequestMapping("/mobileLogin.action")
	public ResponseEntity<String> mobileLogin(HttpServletRequest request,HttpServletResponse response){
		String userCode=request.getParameter("userName"); //用户id
		String passWord=request.getParameter("passWord"); //密码
		UserLoginVo returnVo=new UserLoginVo();
		try{
			Map<String,String> loginResult=userLoginService.commonLogin(userCode, passWord);
			if("Y".equals(MapUtils.getString(loginResult, "flag"))){
				//成功
				returnVo.setFlag("1");
				//logger.info();
			}else{
				//失败
				returnVo.setFlag("0");
				returnVo.setFailReason(MapUtils.getString(loginResult, "errorMsg"));
			}
		}catch(Exception e){
			e.printStackTrace();
			returnVo.setFlag("0");
			returnVo.setFailReason("系统错误");
		}
		return SpringMVCResult.returnResponseEntity(JSON.toJSONString(returnVo));
	}
	
	
	
}
